package com.bubblegumproject.ogo.action;

/**
 * The Result of some chain of action processing.
 *
 * XXX: Get rid of this class
 *
 * @author Azubuko Obele (buko.obele@gmail.com)
 */
public class Result {

    private boolean success;

    private int code;

    private String message;

    public Result(boolean success, int code, String result) {
        assert(result != null);
        this.success = success;
        this.code = code;
        this.message = result;
    }

    public boolean isSuccess() {
        return success;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public static Result Success(int code, String msg) {
        return new Result(true, code, msg);
    }

    public static Result Fail(int code, String msg) {
        return new Result(false, code, msg);
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Result result = (Result) o;

        return (code == result.code) && (success == result.success);
    }


    public int hashCode() {
        int result;
        result = (success ? 1 : 0);
        result = 31 * result + code;
        return result;
    }
}
